#region Namespace References

using System;
using System.Collections;
using System.Collections.Generic;
using DynConDevCorp.OpenArch.SmartData.Interfaces;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.Interfaces
{
    /// <summary>
    /// Base Interface for collections of ISmartEntity objects.
    /// </summary>
    public interface ISmartEntityCollection : ISmartFieldCollection, ISmartEntity
    {
        #region Public Instance Properties

        /// <summary>
        /// Gets the type of the entity.
        /// </summary>
        /// <value>The type of the entity.</value>
        Type EntityType { get; }


        #endregion

        #region Public Instance Methods

        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Add(ISmartEntity entity);

        /// <summary>
        /// Gets the raw enumerator.
        /// </summary>
        /// <returns></returns>
        IEnumerator RawEnumerator();

        /// <summary>
        /// News the entity.
        /// </summary>
        /// <returns></returns>
        ISmartEntity NewEntity();

        /// <summary>
        /// News the entity.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <returns></returns>
        ISmartEntity NewEntity(Guid identity);

        /// <summary>
        /// Gets the entity.
        /// </summary>
        /// <typeparam name="TReturn">The type of the ETUR n_ ENTIT y_ TYPE.</typeparam>
        /// <param name="identity">The identity.</param>
        /// <returns></returns>
        TReturn GetEntity<TReturn>(Guid identity) where TReturn : ISmartEntity;

        /// <summary>
        /// Gets the entity.
        /// </summary>
        /// <typeparam name="TReturn">The type of the ETUR n_ ENTIT y_ TYPE.</typeparam>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        TReturn GetEntity<TReturn>(int index) where TReturn : ISmartEntity;

        /// <summary>
        /// Gets the entities.
        /// </summary>
        /// <typeparam name="TReturn">The type of the ETUR n_ ENTIT y_ TYPE.</typeparam>
        /// <returns></returns>
        IEnumerable<TReturn> GetEntities<TReturn>() where TReturn : ISmartEntity;


        #endregion
    }

    /// <summary>
    /// Type Safe Interface for collections of ISmartEntity objects.
    /// </summary>
    /// <typeparam name="TEntity">
    /// The type of the item contained in the collection. 
    /// Must be derived from ISmartEntity.
    /// </typeparam>
    public interface ISmartEntityCollection<TEntity> : ISmartEntityCollection  //, ISmartFieldKeyedCollection<TEntity>
        where TEntity : ISmartEntity
    {
        #region Public Instance Methods

        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Add(TEntity entity);

        /// <summary>
        /// Removes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        bool Remove(TEntity entity);

        /// <summary>
        /// Gets the entity.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <returns></returns>
        TEntity GetEntity(Guid identity);

        /// <summary>
        /// Gets the entity.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        TEntity GetEntity(int index);

        /// <summary>
        /// Gets the entities.
        /// </summary>
        /// <returns></returns>
        IEnumerable<TEntity> GetEntities();

        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        bool TryGetValue(Guid id, out TEntity value);

        /// <summary>
        /// Determines whether [contains] [the specified entity].
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified entity]; otherwise, <c>false</c>.
        /// </returns>
        bool Contains(TEntity entity);


        /// <summary>
        /// Determines whether [contains] [the specified entity ID].
        /// </summary>
        /// <param name="entityID">The entity ID.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified entity ID]; otherwise, <c>false</c>.
        /// </returns>
        bool Contains(Guid entityID);

        /// <summary>
        /// Creates the new entity.
        /// </summary>
        /// <returns></returns>
        /// 
        TEntity CreateNewEntity();

        /// <summary>
        /// Re-create entity with specific identity.
        /// </summary>
        /// <param name="EntityID">The entity ID.</param>
        /// <returns></returns>
        TEntity ReCreateEntity(Guid EntityID);

        #endregion
    }
}